<?php

/**
 * ClassName:帖子列表详情查询器
 * @auditor LeiJunXiang
 * @time 2024/11/19
 */

namespace app\tool\inviteList;

use app\factory\Factory;
use app\model\invite\Comment;
use app\modelOpreate\invite\Invite;
use app\tool\ToolBase;

class PostListSelect extends ToolBase
{
    const TOOL_POST_LIST_SELECT = "PostListSelect";
    //帖子对象key
    protected $postObjKey;
    //帖子信息
    protected $postMsg;
    //评论信息
    protected $descMsg;
    //帖子详情
    protected $postDetail;

    /**
     * (帖子详情)开始查询(帖子对象key)
     */
    public function startSelect($postObjKey)
    {
        $reData = [];
        if($postObjKey){
            //初始化数据
            $this->initData($postObjKey);
            //获取帖子信息
            $this->getPostMsg();
            //获取评论信息
            $this->getDescMsg();
            //生成帖子详情数组
            $this->createpostDetail();
            $reData = $this->postDetail;
            //清除数据
            $this->cleanData();
        }else{
            $this->errMsg = "请传入正确参数";
            $this->errCode = FAIL;
        }
        return $reData;
    }
    /**
     * 初始化数据
     */
    protected function initData($postObjKey)
    {
        //帖子对象key
	    $this->postObjKey = $postObjKey;
        //帖子信息
	    $this->postMsg = "";
        //评论信息
	    $this->descMsg = "";
        //帖子详情
	    $this->postDetail = "";
        $this->errCode = SUCCESS;
        $this->errMsg = "";
        }
    /**
     * 获取帖子信息
     */
    protected function getPostMsg()
    {
        $toolObj = Factory::getInstance()->getToolObj(Invite::TOOL_INVITE_OPE);
        //根据帖子对象key查询指定的帖子信息
        $postMsg = $toolObj->selectPostDetailsByObjKey($this->postObjKey);
        if(empty($postMsg)){
            $this->errMsg = "帖子获取失败";
            $this->errCode = FAIL;
            return;
        }
        $this->postMsg = $postMsg;

    }
    /**
     * 获取评论信息
     */
    protected function getDescMsg()
    {
        if(!$this->isGoOn()){
            return;
        }
        $obj = Comment::createObj();
        //查询评论（父对象key，页数，条数，展示子评论条数）
        $comments = $obj->selectComment($this->postObjKey, 1, 10, 3);
        $this->descMsg = $comments;
        }
    /**
     * 生成帖子详情数组
     */
    protected function createpostDetail()
    {
        if(!$this->isGoOn()){
            return;
        }
        $this->postMsg['commentCountList'] = $this->descMsg;
        $this->postDetail = $this->postMsg;
    }
/**
 * 清除数据
 */
    protected function cleanData()
    {
        $this->postObjKey = "";
        $this->postMsg = "";
        $this->descMsg = "";
        $this->postDetail = "";
    }


}